package com.intelligentmeterreadingsys.usermanager.activity;



import com.intelligentmeterreadingsys.R;
import com.intelligentmeterreadingsys.waterbanding.activity.WaterBandingMainActivity;



import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.RelativeLayout;

/**
 * 用户信息查询
 * @author king
 *
 */
public class UserWaterInfoMainActivity extends ActivityGroup{
  
	public LinearLayout container;
	
	public RadioButton button;//查询
	
	public RadioButton button2;//条件
	
	public RadioGroup group;
	
	
	
	public String usernumber;
	
	public String name;
	
	public String adds;
	
	public String type;
	
	public String phone;
	
	
	
	public boolean b=false;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.usewaterinfomain);
		
		init();
	}
	
	/**
	 * 初始化控件
	 */
	public void init(){
		container=(LinearLayout)findViewById(R.id.usewater_linear);
		button=(RadioButton)findViewById(R.id.usermanager_userinfo_query);
		button2=(RadioButton)findViewById(R.id.usermanager_userinfo_tiaojian);
		group=(RadioGroup)findViewById(R.id.usermanageer_info_radiogroup);
		
		group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				if(checkedId==button.getId()){
					Bundle bundle=new Bundle();
					System.out.println(phone+"phone");
					bundle.putString("username", name);
					bundle.putString("number",usernumber);
					bundle.putString("phone", phone);
					bundle.putString("adds", adds);
					bundle.putString("type",type);
					bundle.putBoolean("key", true);
					
					launchActivity(System.currentTimeMillis()+"",UseWaterInfoActivity.class,bundle);
				}else if(checkedId==button2.getId()){
					
					launchActivity("UserInfoConditionActivity",UserInfoConditionActivity.class,null);	
					final UserInfoConditionActivity   activity=(UserInfoConditionActivity)getCurrentActivity();
				       Button button5=	activity.button1;
				button5.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						System.out.println("-------------");
					name=activity.edit1.getEditableText().toString();
					usernumber=activity.edit2.getEditableText().toString();
					phone=activity.edit3.getEditableText().toString();
					adds=activity.edit4.getEditableText().toString();
					type=activity.usertype;
					button.setChecked(true);
						b=true;
					}
				});
				}
				
			}
		});
		
	
        Bundle bundle=new Bundle();
        bundle.putBoolean("key", false);
		launchActivity("UseWaterInfoActivity",UseWaterInfoActivity.class,bundle);
	}
	/**
	 * 界面切换
	 * @param id
	 * @param activityClass
	 */
	public void launchActivity(String id, Class<?> activityClass,Bundle bundle) {
        container.removeAllViews();
        
        Intent intent =  new Intent(UserWaterInfoMainActivity.this, activityClass);
        if(bundle!=null){
        	
        	intent.putExtras(bundle);
        }
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        
        Window window = getLocalActivityManager().startActivity(id, intent);
       
        View view = window.getDecorView();
        
        container.addView(view);
    }
}
